{extend name="common/base"/}
{block name="style"}
<style>
	.gougu-upload-files{background-color: #ffffff; border:1px solid #e4e7ed;color: #c0c4cc;cursor: not-allowed; padding:0 12px; width:180px; box-sizing: border-box; display: inline-block; font-size: inherit; height: 38px; line-height: 35px; margin-right:8px; border-radius:2px;}
	.gougu-upload-tips{color:#969696}
	.layui-form-item{margin-bottom:8px;}
	.layui-input-block{min-height:24px;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
	<table class="layui-hide" id="test" lay-filter="test"></table>
</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-normal layui-btn-sm" title="添加" lay-event="add">+ 添加</span>
	</div>
</script>

<script type="text/html" id="barDemo">
	<div class="layui-btn-group"><span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span><span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span></div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table, tool = layui.tool ,form = layui.form,laydate = layui.laydate,upload=layui.upload;
		layui.pageTable = table.render({
			elem: '#test',
			title: '数据列表',
			toolbar: '#toolbarDemo',
			defaultToolbar:['filter', {title:'导出EXCEL',layEvent: 'LAYTABLE_EXCEL',icon: 'layui-icon-export'}],
			url: "/matter/general_material/index", //数据接口
			cellMinWidth: 80,
			page: true, //开启分页
			limit: 16,
			cols: [
				[ //表头
					{
						field: 'id',
						title: '编号',
						align: 'center',
						width: 80
					},
					{
						field: 'name',
						title: '材料名称',
						align: 'center'
					},
					{
						field: 'sort',
						title: '排序',
						align: 'center'
					},
					{
						field: 'right',
						title: '操作',
						toolbar: '#barDemo',
						width: 100,
						align: 'center'
					}
				]
			]
		});
		$('[lay-filter="clear"]').on('click',function(){
			setTimeout(function(){
				$('[lay-filter="webform"]').click();
			},10)
		})
		//表头工具栏事件
		table.on('toolbar(test)', function(obj){
			if (obj.event === 'add') {
				tool.side("/matter/general_material/add");
				return;
			}
			//导出excel
			if(obj.event === 'LAYTABLE_EXCEL'){
				var formSelect = form.val('barsearchform');
				formSelect.limit=99999;
				$.ajax({
					url: '/matter/general_material/index',
					data: formSelect,
					success:function(res){
						table.exportFile('test', res.data,'xls');
					}
				});
				return;
			}
		});
		//监听行工具事件
		table.on('tool(test)', function(obj) {
			var data = obj.data;
			if(obj.event === 'edit'){
				tool.side('/matter/general_material/add?id='+data.id);
				return;
			}
			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (res) {
						layer.msg(res.msg);
						if (res.code == 0) {
							obj.del();
						}
					}
					tool.delete("/matter/general_material/delete", {id: data.id}, callback);
					layer.close(index);
				});
			}
		});
	}
</script>
{/block}
<!-- /脚本 -->
